﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace WindowsFormsApplication1
{
    static class Feed
    {
        public static EventWaitHandle myEventWaitHandle = new ManualResetEvent (false);
        static PricesData MyPricesData;
        
        public static void set_PricesData(PricesData ThePricesData)
        {
            MyPricesData = ThePricesData ;
        }

        public static int timeWait = 10;

        public static void Feeding()
        {
            int index = 0; 
            while (true)
            {
                myEventWaitHandle.WaitOne();
                System.Threading.Thread.Sleep(timeWait);
                
                if(MyPricesData.MyDataDico.Count > 0 ){

                    lock (MyPricesData.MyDataDico)
                    {
                        if(index == 10000) index = 0;
                        MyPricesData.UpdateTab(MyPricesData.MyDataDico.Keys.ElementAt(RandomProvider.Next(0,MyPricesData.MyDataDico.Count)), RandomProvider.NextNormal() );
                        Console.WriteLine("index:" + MyPricesData.MyDataDico.Keys.ElementAt(RandomProvider.Next(0, MyPricesData.MyDataDico.Count)) + " Normal : " + RandomProvider.NextNormal());
                        index++;
                    }
                }
            }

        }

    }
}
